package com.cqie.controller.user;

import com.cqie.dto.user.DoctorInfoDto;
import com.cqie.exception.SpecialException;
import com.cqie.service.IDoctorInfoService;
import com.cqie.util.ResultTemplate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 不吃海鲜
 * @since 2024-11-25
 */
@Tag(name = "医生信息Controller", description = "描述：医生信息接口")
@RestController
@RequestMapping({"/api/v1.0/doctorInfo", "/api/v1/doctorInfo"})
public class DoctorInfoController {

    private final IDoctorInfoService doctorInfoService;

    public DoctorInfoController(IDoctorInfoService doctorInfoService) {
        this.doctorInfoService = doctorInfoService;
    }

    @Operation(summary = "获取医生基本信息")
    @GetMapping(value = "/getDoctorInfo")
    public ResultTemplate<DoctorInfoDto> getDoctorInfo() {
        return ResultTemplate.Success(doctorInfoService.getDoctorInfo());
    }

    @Operation(summary = "保存 / 更新 医生基本信息")
    @PostMapping(value = "/saveDoctorInfo")
    public ResultTemplate<Boolean> saveDoctorInfo(@RequestBody DoctorInfoDto doctorInfoDto) {
        return ResultTemplate.Success(doctorInfoService.saveDoctorInfo(doctorInfoDto));
    }

    @Operation(summary = "查询科室下的医生信息")
    @Parameters({
            @Parameter(name = "departmentCode", description = "科室编码", required = true)
    })
    @GetMapping(value = "/queryDoctorInfoUnderDepartment")
    public ResultTemplate<List<DoctorInfoDto>> queryDoctorInfoUnderDepartment(@RequestParam(required = true) String departmentCode) throws SpecialException {
        if (ObjectUtils.isEmpty(departmentCode)){
            throw new SpecialException("科室编码不能为空");
        }
        return ResultTemplate.Success(doctorInfoService.queryDoctorInfoUnderDepartment(departmentCode));
    }

}
